package com.codechuan.hallo_web.utils;

import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

public class RedisUtils {

    public static Long incrementKeyWithExpireTime(StringRedisTemplate redisTemplate, String key) {
        // 递增键
        Long newValue = redisTemplate.opsForValue().increment(key);
        // 设置过期时间
        long expireTimeInSeconds = 7 * 24 * 60 * 60;
        redisTemplate.expire(key, expireTimeInSeconds, TimeUnit.SECONDS);
        return newValue;
    }

    public static Long incrementKeyWithExpireTimeTxm(StringRedisTemplate redisTemplate, String key) {
        // 递增键
        Long newValue = redisTemplate.opsForValue().increment(key);
        // 设置过期时间
        long expireTimeInSeconds = 10000;
        redisTemplate.expire(key, expireTimeInSeconds, TimeUnit.SECONDS);
        return newValue;
    }
}
